/**
 * A singular factory that contains all of the DateTime-factories needed in the Twitter processing.
 */
package org.hackystat.ui.hackerrific.server;

import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

/**
 * A singular factory that contains all of the DateTime-factories needed in the Twitter processing.
 * @author David J Nickles
 * 
 */
public class SimpleDateFactories {
  
  private static SimpleDateFactories singular;

  private SimpleDateFormat twitterfactory;
  private SimpleDateFormat httpfactory;
  private SimpleDateFormat gmtfactory;
  private SimpleDateFormat localfactory;

  /**
   * Construct all the DateTime product lines in this factory.
   */
  private SimpleDateFactories() {
    initDateTimeFactories();
  }
  
  /**
   * This method constructs the DateTimeFactories that will be used to manipulate timestamps.
   */
  private void initDateTimeFactories() {
    Locale locale = Locale.ENGLISH;
    // Twitter time: <created_at>Wed Oct 17 18:53:11 +0000 2007</created_at>
    this.twitterfactory = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", locale);
    this.twitterfactory.setTimeZone(TimeZone.getTimeZone("GMT"));
    this.httpfactory = new SimpleDateFormat("EEE,+d+MMM+yyyy+HH:mm:ss'+GMT'", locale);
    this.httpfactory.setTimeZone(TimeZone.getTimeZone("GMT"));
    this.gmtfactory = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", locale);
    this.gmtfactory.setTimeZone(TimeZone.getTimeZone("GMT"));
    this.localfactory = new SimpleDateFormat("EEE, MMM dd, h:mma", locale);
    /* this one takes the local time zone defined in the JVM */
  }
  
  /**
   * @return a singular reference to a SDVDateTimeFactory that this class maintains.
   */
  public static SimpleDateFactories getInstance() {
    if (singular == null) {
      return (singular = new SimpleDateFactories());
    } 
    else {
      return singular;
    }
  }

  /**
   * @return the twitterfactory
   */
  public SimpleDateFormat getTwitterfactory() {
    return this.twitterfactory;
  }

  /**
   * @return the httpfactory
   */
  public SimpleDateFormat getHttpfactory() {
    return this.httpfactory;
  }

  /**
   * @return the gmtfactory
   */
  public SimpleDateFormat getGMTfactory() {
    return this.gmtfactory;
  }

  /**
   * @return the localfactory
   */
  public SimpleDateFormat getHeaderfactory() {
    return this.localfactory;
  }
}
